home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / winsrc.arc / MAINFRAC.C < prev    next >
C/C++ Source or Header  |  1991-06-16  |  15KB  |  581 lines

  1. /*
  2.    non-windows main driver of Fractint for Windows - 
  3. */
  4.  
  5.  
  6. #define PUTTHEMHERE 1        /* stuff common external arrays here */
  7.  
  8. /* from MSC's <dos.h> */
  9. #define FP_SEG(fp) (*((unsigned _far *)&(fp)+1))
  10. #define FP_OFF(fp) (*((unsigned _far *)&(fp)))
  11.  
  12. #include "fractint.h"
  13. #include "fractype.h"
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <search.h>
  18. #include <string.h>
  19. #include <float.h>
  20. #include <ctype.h>
  21. #include <time.h>
  22.  
  23. int cmp_line(), pot_line();
  24.  
  25. LPSTR win_lpCmdLine;
  26.  
  27. extern int time_to_restart;
  28. extern int time_to_reinit;
  29. extern int time_to_quit;
  30. extern int time_to_load;
  31. extern int time_to_save;
  32. extern int time_to_print;
  33. extern int time_to_cycle;
  34.  
  35. extern char FileName[];
  36. char string004[2];
  37.  
  38. unsigned char textcolor[27];
  39.  
  40. extern int xdots, ydots, colors, maxiter;
  41. extern int ytop, ybottom, xleft, xright;
  42.  
  43. int fractype;
  44. extern int invert;
  45.  
  46. double ftemp, xxmin, xxmax, yymin, yymax;
  47. long fudge;
  48. double xfudge;
  49.  
  50. long xvalue, yvalue;
  51. extern long lm, linitx, linity;
  52. int maxit, bitshift;
  53. extern int color, row, col;
  54.  
  55. int calc_status; /* -1 no fractal            */
  56.          /*  0 parms changed, recalc reqd   */
  57.          /*  1 actively calculating        */
  58.          /*  2 interrupted, resumable        */
  59.          /*  3 interrupted, not resumable   */
  60.          /*  4 completed            */
  61.  
  62. extern int reset_periodicity;
  63. extern int cpu;
  64. extern int kbdcount;
  65. extern int max_kbdcount;
  66. extern int show_orbit;
  67. extern int orbit_ptr;
  68. extern int periodicitycheck;
  69. extern int debugflag;
  70. int integerfractal;
  71. extern int distest;
  72. int oktoprint = 0;
  73. extern int bitshiftless1;
  74. char usr_stdcalcmode, stdcalcmode;
  75. int  usr_distest;
  76. int usr_floatflag, usr_periodicitycheck;
  77.  
  78. long creal, cimag;
  79. long delx, dely, delx2, dely2, delmin;
  80. long xmin, xmax, ymin, ymax, x3rd, y3rd;
  81. double  dxsize, dysize;        /* xdots-1, ydots-1        */
  82. double delxx, delyy, delxx2, delyy2, ddelmin, xx3rd, yy3rd;
  83. double param[4];
  84. double potparam[3];
  85. int diskvideo, savedac;
  86. long calctime;
  87. int mode7text, textsafe;
  88.  
  89. #define MAXLINE  2048
  90.  
  91. long   far *lx0, far *ly0, far *lx1, far *ly1;
  92. double far *dx0, far *dy0, far *dx1, far *dy1;
  93. extern double far *temp_array;
  94.  
  95. extern unsigned char trigndx[4];
  96.  
  97. unsigned char dacbox[257][3];
  98. double plotmx1, plotmx2, plotmy1, plotmy2;
  99. extern int MPOverflow;
  100. int dotmode;
  101. extern int pot16bit;
  102. int andcolor, resave_flag;
  103. extern int timer_interval;
  104. extern int active_ovly;
  105.  
  106. int extraseg;
  107. int timedsave = 0;
  108. int disk16bit = 0;
  109. extern int initbatch;
  110. float far initifs3d[32][13];
  111. float far initifs[32][7];
  112. extern unsigned char readname[];
  113. unsigned char MAP_name[40] = "";
  114. int rowcount;
  115. int adapter;
  116. extern int showfile;
  117. extern int initmode;
  118. extern int overlay3d;
  119. extern int display3d;
  120. extern int filetype;
  121. int comparegif = 0;
  122. int diskisactive = 0;
  123. extern int initsavetime;
  124. int saveticks = 0;
  125. int savebase = 0;
  126. int zwidth = 0;
  127. extern int (*outln)();
  128. extern int out_line();
  129. extern int outlin16();
  130. static int call_line3d();
  131. extern int line3d();
  132. extern int gifview();
  133. extern int tgaview();
  134. int hasconfig = 0;
  135. FILE *dacfile;
  136. int mapset = 0;
  137. int reallyega = 0;
  138. int loadPalette = 0;
  139. int compiled_by_turboc = 0;
  140.  
  141. int     sxdots,sydots;
  142. int     sxoffs=0,syoffs=0;
  143. int     viewwindow=0;
  144. float   viewreduction=1;
  145. int     viewcrop=1;
  146. float   finalaspectratio;
  147. int     viewxdots=0,viewydots=0;
  148. extern int filexdots, fileydots, filecolors;
  149. int frommandel;
  150.  
  151. int debug_fastupdate;        /* debugging - update every pixel if set */
  152.  
  153. int onthelist[100];        /* list of available fractal types */
  154. int CountFractalList;           /* how many are on the list? */
  155. extern int CurrentFractal;        /* which one is current? */
  156.  
  157. int Printer_Resolution, Printer_Titleblock, Printer_SFrequency;
  158. int Printer_SetScreen, Printer_SStyle, Printer_Type;
  159. int Printer_ColorXlat, Printer_SAngle, LPTnumber;
  160. int EPSFileType, Print_To_File, Printer_CRLF;
  161. int video_type, no_color_text;
  162.  
  163. int Distribution = 30, Offset = 0, Slope = 25;
  164. long con;
  165.  
  166. int active_system = WINFRAC;    /* running under windows */
  167. extern int win_display3d, win_overlay3d;
  168.  
  169. int iit = 0;
  170. int vesa_detect;
  171. int far videotable[2];
  172. int release = 1600;
  173. char busy;
  174. int started_resaves = 0;
  175. int gotrealdac = 1;
  176. void    (*outln_cleanup)();
  177. extern int fpu;
  178. int TranspSymmetry;
  179.  
  180. compare_fractalnames( const void *element1, const void *element2)
  181. {
  182. int i, j, k;
  183.     j = *(int*)element1;
  184.     k = *(int*)element2;
  185. for (i = 0; i < 100; i++) {
  186.     if (fractalspecific[j].name[i] < fractalspecific[k].name[i])
  187.         return(-1);
  188.     if (fractalspecific[j].name[i] > fractalspecific[k].name[i])
  189.         return(1);
  190.     if (fractalspecific[j].name[i] == 0)
  191.         return(0);
  192.     }
  193. return(0);
  194. }
  195.  
  196. fractint_main()
  197. {
  198. int i, j, k;
  199. long newx, newy, newxx, newyy, newxy, temp;
  200. double temp1, temp2;
  201. double dtemp, ccreal, ccimag;
  202.  
  203. outln_cleanup = NULL;        /* outln routine can set this */
  204.  
  205. CountFractalList = 0;
  206. for (k = 0; fractalspecific[k].name != NULL; k++)
  207.    if (fractalspecific[k].name[0] != '*' &&
  208.        (fractalspecific[k].flags & WINFRAC) != 0 &&
  209.        CountFractalList < 100) 
  210.             onthelist[CountFractalList++] = k;
  211. qsort(onthelist,CountFractalList,2,compare_fractalnames);
  212. CurrentFractal = fractype;
  213.  
  214. lx0 = (long far *)&temp_array[0*MAXLINE];
  215. ly0 = (long far *)&temp_array[1*MAXLINE];
  216. lx1 = (long far *)&temp_array[2*MAXLINE];
  217. ly1 = (long far *)&temp_array[2*MAXLINE];
  218. dx0 = (double far *)&temp_array[0*MAXLINE];
  219. dy0 = (double far *)&temp_array[1*MAXLINE];
  220. dx1 = (double far *)&temp_array[2*MAXLINE];
  221. dy1 = (double far *)&temp_array[2*MAXLINE];
  222. extraseg = FP_SEG(dx0);
  223.  
  224. restoredac();        /* ensure that the palette has been initialized */
  225.  
  226. win_cmdfiles();                /* SSTOOLS.INI processing */
  227.  
  228. initmode = 1;                           /* override SSTOOLS.INI */
  229.  
  230. dotmode = 1;
  231. diskvideo = 0;
  232. usr_distest = 0;
  233.  
  234. max_kbdcount=(cpu==386) ? 80 : 30; /* check the keyboard less often */
  235.  
  236. /* ----- */
  237.  
  238. debug_fastupdate = 0;
  239. calc_status = -1;
  240. resave_flag = 1;
  241. strcpy(FileName,"Fract001");
  242. if (showfile != 0) {
  243.     strcpy(readname, FileName);
  244.     }
  245. else {
  246.     if (strchr(readname,'.') == NULL)
  247.      strcat(readname,".gif");
  248.     strcpy(FileName,readname);
  249.     time_to_load = 1;
  250.     }
  251.  
  252. if (debugflag == 23232) {   /* check for free memory */
  253.    char temp[50];
  254.    sprintf(temp," %d bytes of free stack space",stackavail());
  255.    stopmsg(0,temp);
  256.    }
  257.  
  258. if (debugflag == 70) fpu = 0;
  259.  
  260. /* ----- */
  261.  
  262. time_to_quit = 0;
  263. if (debugflag == 23232) /* give the Windows stuff control first */
  264.     getakey(); 
  265. if (time_to_quit)
  266.     return(0);
  267.  
  268. reinit:
  269.     time_to_reinit = 0;
  270.  
  271.     savedac = 0;             /* don't save the VGA DAC */
  272.  
  273.     for (i = 0; i < 4; i++) {
  274.         if(param[i] != FLT_MAX)
  275.             fractalspecific[fractype].paramvalue[i] = param[i];
  276.         else
  277.             param[i] = fractalspecific[fractype].paramvalue[i];
  278.         }
  279.     ccreal = param[0]; ccimag = param[1]; /* default C-values */
  280.     frommandel = 0;
  281.  
  282.     if (xxmin > xxmax) {
  283.        dtemp = xxmin; xxmin = xxmax; xxmax = dtemp;} 
  284.     if (yymin > yymax) {
  285.        dtemp = yymin; yymin = yymax; yymax = dtemp;} 
  286.  
  287.     ytop    = 0;
  288.     ybottom = ydots-1;
  289.     xleft   = 0;
  290.     xright  = xdots-1;
  291.     filexdots = xdots;
  292.     fileydots = ydots;
  293.     filecolors = colors;
  294.  
  295. restart:
  296.     time_to_restart = 0;
  297.  
  298.     if (calc_status == -99)
  299.         calc_status = 2;            /* force a recalc */
  300.     else
  301.         calc_status = 0;            /* force a restart */
  302.  
  303.     maxit = maxiter;
  304.  
  305.     if (colors == 2 && (fractype == PLASMA || usr_stdcalcmode == 'b'))
  306.         colors = 16;         /* 2-color mode just doesn't work on these */
  307.  
  308.     andcolor = colors-1;
  309.  
  310.     debug_fastupdate = 0;    /* turn off debug-mode screen updates */
  311.     if (debugflag == 6666)
  312.         debug_fastupdate = 1;
  313.  
  314.     /* compute the (new) screen co-ordinates */
  315.     /* correct a possibly munged-up zoom-box outside the image range */
  316.     if (ytop    >= ydots) ytop    = ydots-1;
  317.     if (ybottom >= ydots) ybottom = ydots-1;
  318.     if (xleft   >= xdots) xleft   = xdots-1;
  319.     if (xright  >= xdots) xright  = xdots-1;
  320.     if (xleft == xright || ytop == ybottom) {
  321.         }
  322.     if (xleft > xright)
  323.         { i = xleft; xleft = xright; xright = i;}
  324.     if (ytop > ybottom)
  325.         { i = ybottom; ybottom = ytop; ytop = i;}
  326.     temp1 = xxmin;
  327.     temp2 = xxmax - xxmin;
  328.     xxmin = temp1 + (temp2 * xleft )/(xdots-1);
  329.     xxmax = temp1 + (temp2 * xright)/(xdots-1);
  330.     temp1 = yymin;
  331.     temp2 = yymax - yymin;
  332.     yymin = temp1 + (temp2 * (ydots - 1 - ybottom)/(ydots-1));
  333.     yymax = temp1 + (temp2 * (ydots - 1 - ytop   )/(ydots-1));
  334.     xx3rd = xxmin;
  335.     yy3rd = yymin;
  336.     xleft   = 0;
  337.     xright  = xdots-1;
  338.     ytop    = 0;
  339.     ybottom = ydots-1;
  340.  
  341. /*
  342.     delxx = (xxmax - xxmin) / (xdots-1);
  343.     delyy = (yymax - yymin) / (ydots-1);
  344.     delxx2 = delyy2 = 0.0;
  345.     ddelmin = fabs(delxx);
  346.     if (fabs(delyy) < ddelmin)
  347.         ddelmin = fabs(delyy);
  348. */
  349.  
  350.     dxsize = xdots - 1;  dysize = ydots - 1;
  351.  
  352.     if (calc_status != 2 && !overlay3d)
  353.         if (!clear_screen(1)) {
  354.             stopmsg(0,"Can't free and re-allocate the image");
  355.             return(0);
  356.             }
  357.  
  358.     dxsize = xdots - 1;  dysize = ydots - 1;
  359.     sxdots = xdots;  sydots = ydots;
  360.     finalaspectratio = ((float)ydots)/xdots;
  361.  
  362.     calcfracinit();
  363.  
  364.     bitshiftless1 = bitshift - 1;
  365.  
  366.     if (time_to_load)
  367.         goto wait_loop;
  368.  
  369.       if(showfile == 0) {        /* loading an image */
  370.      if (display3d)         /* set up 3D decoding */
  371.         outln = call_line3d;
  372.      else if(filetype >= 1)     /* old .tga format input file */
  373.         outln = outlin16;
  374.      else if(comparegif)        /* debug 50 */
  375.         outln = cmp_line;
  376.      else if(pot16bit) {        /* .pot format input file */
  377.         pot_startdisk();
  378.         outln = pot_line;
  379.         }
  380.      else                /* regular gif/fra input file */
  381.         outln = out_line;
  382.      if(filetype == 0)
  383.         i = funny_glasses_call(gifview);
  384.      else
  385.         i = funny_glasses_call(tgaview);
  386.      if(i == 0)
  387.         buzzer(0);
  388.      else {
  389.         calc_status = -1;
  390.         }
  391.      }
  392.  
  393.       if(showfile == 0) {        /* image has been loaded */
  394.      showfile = 1;
  395.      if (initbatch == 1 && calc_status == 2)
  396.         initbatch = -1; /* flag to finish calc before save */
  397.      if (calc_status == 2) goto try_to_resume;
  398.      }
  399.       else {                /* draw an image */
  400.  
  401. try_to_resume:
  402.  
  403.      diskisactive = 1;        /* flag for disk-video routines */
  404.      if (initsavetime != 0        /* autosave and resumable? */
  405.        && (fractalspecific[fractype].flags&NORESUME) == 0) {
  406.         savebase = readticker(); /* calc's start time */
  407.         saveticks = (long)initsavetime * 1092; /* bios ticks/minute */
  408.         if ((saveticks & 65535) == 0)
  409.            ++saveticks; /* make low word nonzero */
  410.         }
  411.          kbdcount = 30;                 /* ensure that we check the keyboard */
  412.      if ((i = calcfract()) == 0)    /* draw the fractal using "C" */
  413.         buzzer(0); /* finished!! */
  414.          saveticks = 0;         /* turn off autosave timer */
  415.          diskisactive = 0;        /* flag for disk-video routines */
  416.      }
  417.  
  418.     overlay3d = 0;      /* turn off overlay3d */
  419.     display3d = 0;      /* turn off display3d */
  420.  
  421.     zwidth = 0;
  422.  
  423.     if (!keypressed()) {
  424.         flush_screen();
  425.         buzzer(3);
  426.         getakey();
  427.         }
  428.  
  429. wait_loop:
  430.  
  431. for (;;) {
  432.     if (time_to_quit)
  433.          return(0);
  434.     if (time_to_load) {
  435.         strcpy(readname, FileName);
  436.         showfile = 1;
  437.         time_to_load = 0;
  438.         time_to_restart = 0;
  439.         overlay3d = win_overlay3d;
  440.         display3d = win_display3d;
  441.         if (win_load() >= 0) {
  442.             showfile = 0;
  443.             rowcount = 0;
  444.             ytop    = 0;        /* reset the zoom-box */
  445.             ybottom = ydots-1;
  446.             xleft   = 0;
  447.             xright  = xdots-1;
  448.             time_to_load = 0;
  449.             time_to_restart = 1;
  450.             if (calc_status == 2) {
  451.                 calc_status = -99;      /* special klooge for restart */
  452.                 }
  453.             }
  454.         win_overlay3d = 0;
  455.         win_display3d = 0;
  456.         }
  457.     if (time_to_save) {
  458.         strcpy(readname, FileName);
  459.         if (readname[0] != 0)
  460.             win_save();
  461.         time_to_save = 0;
  462.         if (calc_status == 2) {
  463.             calc_status = -99;
  464.             time_to_restart = 1;
  465.             }
  466.         }
  467.     if (time_to_print) {
  468.         win_print();
  469.         time_to_print = 0;
  470.         }
  471.     if (time_to_cycle) {
  472.        win_cycle();
  473.        }
  474.     if (time_to_reinit)
  475.          goto reinit;
  476.     if(time_to_restart)
  477.          goto restart;
  478.     getakey();
  479.     }
  480.  
  481. }
  482.  
  483. /* displays differences between current image file and new image */
  484. /* Bert - suggest add this to video.asm */
  485. int cmp_line(unsigned char *pixels, int linelen)
  486. {
  487.    static errcount;
  488.    static FILE *fp = NULL;
  489.    extern int rowcount;
  490.    int row,col;
  491.    int oldcolor;
  492.    char *timestring;
  493.    time_t ltime;
  494.    if(fp == NULL)
  495.       fp = fopen("cmperr",(initbatch)?"a":"w");
  496.    if((row = rowcount++) == 0)
  497.       errcount = 0;
  498.    if(pot16bit) { /* 16 bit info, ignore odd numbered rows */
  499.       if((row & 1) != 0) return(0);
  500.       row >>= 1;
  501.       }
  502.    for(col=0;col<linelen;col++) {
  503.       oldcolor=getcolor(col,row);
  504.       if(oldcolor==pixels[col])
  505.      putcolor(col,row,0);
  506.       else {
  507.      if(oldcolor==0)
  508.         putcolor(col,row,1);
  509.      ++errcount;
  510.      if(initbatch == 0)
  511.         fprintf(fp,"#%5d col %3d row %3d old %3d new %3d\n",
  512.            errcount,col,row,oldcolor,pixels[col]);
  513.      }
  514.       }
  515.    if(row+1 == ydots && initbatch) {
  516.       time(<ime);
  517.       timestring = ctime(<ime);
  518.       timestring[24] = 0; /*clobber newline in time string */
  519.       fprintf(fp,"%s compare to %s has %5d errs\n",timestring,readname,errcount);
  520.       }
  521.    return(0);
  522. }
  523.  
  524. int pot_line(unsigned char *pixels, int linelen)
  525. {
  526.    extern int rowcount;
  527.    int row,col,saverowcount;
  528.    if (rowcount == 0)
  529.       pot_startdisk();
  530.    saverowcount = rowcount;
  531.    row = (rowcount >>= 1);
  532.    if ((saverowcount & 1) != 0) /* odd line */
  533.       row += ydots;
  534.    else             /* even line */
  535.       if (dotmode != 11) /* display the line too */
  536.      out_line(pixels,linelen);
  537.    for (col = 0; col < xdots; ++col)
  538.       writedisk(col+sxoffs,row+syoffs,*(pixels+col));
  539.    rowcount = saverowcount + 1;
  540.    return(0);
  541. }
  542.  
  543. static int call_line3d(unsigned char *pixels, int linelen)
  544. {
  545.    /* this routine exists because line3d might be in an overlay */
  546.    return(line3d(pixels,linelen));
  547. }
  548.  
  549. win_cmdfiles()   /* convert lpCmdLine into argc, argv */
  550. {
  551. int i, j, k;
  552. int argc;
  553. char *argv[10];
  554. unsigned char arg[501];   /* max 10 args, 450 chars total */
  555.  
  556. arg[0] = 0;
  557. for (i = 0; i < 10; i++)
  558.    argv[i] = &arg[0];
  559. argc = 1;
  560. strcpy(&arg[1],"winfract.exe");
  561. argv[argc-1] = &arg[1];
  562.  
  563. for (i = 0; i < 460 && win_lpCmdLine[i] != 0; i++)
  564.    arg[20+i] = win_lpCmdLine[i];
  565. arg[20+i] = 0;
  566. arg[21+i] = 0;
  567.  
  568. for (k = 20; arg[k] != 0; k++) {
  569.     while(arg[k] <= ' ' && arg[k] != 0) k++;
  570.     if (arg[k] == 0) break;
  571.     if (argc >= 10) break;
  572.     argc++;
  573.     argv[argc-1] = &arg[k];
  574.     while(arg[k] > ' ')k++;
  575.     arg[k] = 0;
  576.     }
  577.  
  578. cmdfiles(argc,argv);
  579.  
  580. }
  581.